blob: b7959143b2dcc67bb9cf9e7342cbd113f5369938 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import { Balances } from '@/lib/balances'
import { cn, formatCurrency } from '@/lib/utils'
import { Participant } from '@prisma/client'
type Props = {
balances: Balances
participants: Participant[]
currency: string
}
export function BalancesList({ balances, participants, currency }: Props) {
const maxBalance = Math.max(
...Object.values(balances).map((b) => Math.abs(b.total)),
)
return (
<div className="text-sm">
{participants.map((participant) => {
const balance = balances[participant.id]?.total ?? 0
const isLeft = balance >= 0
return (
<div
key={participant.id}
className={cn('flex', isLeft || 'flex-row-reverse')}
>
<div className={cn('w-1/2 p-2', isLeft && 'text-right')}>
{participant.name}
</div>
<div className={cn('w-1/2 relative', isLeft || 'text-right')}>
<div className="absolute inset-0 p-2 z-20">
{formatCurrency(currency, balance)}
</div>
{balance !== 0 && (
<div
className={cn(
'absolute top-1 h-7 z-10',
isLeft
? 'bg-green-200 dark:bg-green-800 left-0 rounded-r-lg border border-green-300 dark:border-green-700'
: 'bg-red-200 dark:bg-red-800 right-0 rounded-l-lg border border-red-300 dark:border-red-700',
)}
style={{
width: (Math.abs(balance) / maxBalance) * 100 + '%',
}}
></div>
)}
</div>
</div>
)
})}
</div>
)
}
|